//app.js
import { ToastPannel } from './component/toastTest/toastTest'  
var config = require('./utils/config');
var net = require('./utils/net.js');
App({
  globalData:{
    selectIndex: {},
    isLogin:false,
    userPhoto:'',
    token:'',
    globalFomIds:[],//数组
    lat:0,
    lon:0,
    orderUserName:'',
    orderUserPhone:'',
    orderBeizhu:'',
    formId:0,
    formId_2:0,
    formId_3:0,
    isInThisCity:false,
    
  },
  statusBarHeight:0,
  userInfo:{},
  ToastPannel,
  onLaunch: function () {
    var that = this;
    wx.getSystemInfo({
      success: res=> {
        this.statusBarHeight = res.statusBarHeight
      },
    })
    
    
    wx.login({
      success: res => {

        console.log('微信返回数据',res);
        if (res.code) {
          console.log('成功，code',res);
          var params = {code:res.code};
         
          net.doRequest(config.service.loginUrl,params,'GET',false,"",res=>{
            
            if(res.code == 0){
              //保存token
              this.globalData.isLogin = true;
              this.globalData.token = res.data.token;
              net.Token = res.data.token;

              if (this.loginCallback) {
                this.loginCallback(res);
              } 
            }
          });
        }
      }

    });
  },


  checkSettingStatu: function (cb) {
    var that = this;
    // 判断是否是第一次授权，非第一次授权且授权失败则进行提醒
    wx.getSetting({
      success: function success(res) {
        var authSetting = res.authSetting;
        if (isEmptyObject(authSetting)) {
          //第一次
        } else {
          // 没有授权的提醒
          if (authSetting['scope.userInfo'] === false) {
            wx.showModal({
              title: '用户未授权',
              content: '如需正常使用该小程序功能，请按确定并在授权管理中选中“用户信息”，然后点按确定。最后再重新进入小程序即可正常使用。',
              showCancel: false,
              success: function (res) {
                if (res.confirm) {
                  wx.openSetting({
                    success: function success(res) {
                      console.log()
                    }
                  });
                }
              }
            })
          } else if (authSetting['scope.userInfo'] === true) {
            //该处用户获取用户的一些授权信息
            if (that.data.userInfo) {
              var nickname = that.data.userInfo.nickName;
              var gender = that.data.userInfo.gender
              //性别 0：未知、1：男、2：女
              if (gender == 1) {
                gender = "True"
              } else if (gender == 2) {
                gender = "False"
              } else {
                gender = "True"
              }

            }
          }
        }
      }
    })
  }
});